$(document).ready(function(){
	showCmTeaInfo();
});
function showCmTeaInfo(){
	//教师列表
	$("#cmTeaInfo").jqGrid({                
		url:global_url+global_urijs+'cmmanage_searchClassTeacherList'+global_suffix+"?cid="+global_cid,
		datatype:"json",                
		mtype:'GET', 
		height:'300',
		width:'720',
		colNames:['教师姓名','职务','是否为管理员','加入时间','操作','isadmin','ctid'],                
		colModel:[                    
		{name:'name_teacher',index:'name_teacher',width:120,align:'center'},                    
		{name:'gname',index:'gname',width:120,align:'center'},                    
		{name:'admin',index:'admin',width:120, sortable:false,align:'center'},
		{name:'ctime_str',index:'ctime_str',width:120,align:'center', sortable:false},
		{name:'option',index:'option',width:120,align:'center', sortable:false},
		{name:'isadmin',index:'isadmin',hidden:true},
		{name:'ctid',index:'ctid',hidden:true}    
		],
		
		//autowidth:true,
		jsonReader: {
			root:"classTeacherList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#cmTeaPage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'ctime_str',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '',
		gridComplete:function(){
			var ids=jQuery("#cmTeaInfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];   
				var is_admin = jQuery("#cmTeaInfo").jqGrid('getRowData', id).isadmin;
				if(is_admin==1){
					sh = "是";
					adm = "<a href='javascript:;' class='jqtrow' onclick='chTel(" + id + ",0)'>取消管理员</a>";
				}else{
					sh = "否";
					adm = "<a href='javascript:;' class='jqtrow' onclick='chTel(" + id + ",1)'>设为管理员</a>";
				}
				
				del = "<a href='javascript:;' class='jqtrow' onclick='delTel_t(" + id + ")'>移除</a>"; 
				jQuery("#cmTeaInfo").jqGrid('setRowData', ids[i], { admin: sh,option: del + " " + adm });
			}
		}
	}).navGrid("#cmTeaPage", { edit: false, add: false, del: false, search: false });
}	
	
	

function showCmStuInfo(){
	//学生列表
	$("#cmStuInfo").jqGrid({                
		url:global_url+global_urijs+'cmmanage_searchClassStudentList'+global_suffix+"?cid="+global_cid,                
		datatype:"json",                
		mtype:'GET', 
		height:'300',
		width:'720',
		colNames:['学生姓名','加入时间','操作','csid'],                
		colModel:[                    
		{name:'sname',index:'sname',width:120,align:'center'},                    
		{name:'ctime_str',index:'ctime_str',width:120,align:'center'},                    
		{name:'option',index:'option',width:120, sortable:false,align:'center'},
		{name:'csid',index:'csid',hidden:true}    
		],
		//autowidth:true,
		jsonReader: {
			root:"classStudentList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#cmStuPage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'ctime_str',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '',
		gridComplete:function(){
			var ids=jQuery("#cmStuInfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i];    
				del = "<a href='javascript:;' class='jqtrow' onclick='delTel_s(" + id + ")'>移除</a>"; 
				jQuery("#cmStuInfo").jqGrid('setRowData', ids[i], { option: del });
			}
		}
	}).navGrid("#cmStuPage", { edit: false, add: false, del: false, search: false });
}

function searchSchoolBuyMethod() {
	var fun = function(data) {
        if(1==data.s){
        	if (data.method == 1) {
        		showCmParInfo1();
        	} else {
        		showCmParInfo2();
        	}
        }
    };
    exeAjax(ajaxUrl(global_url+global_urijs+"cmmanage_searchSchoolBuyMethod"+global_suffix), fun, 
    {
        "cid" :global_cid
    });
	
}


function showCmParInfo1(){
	//家长列表
	$("#cmParInfo").jqGrid({                
		url:global_url+global_urijs+'cmmanage_searchClassParentList'+global_suffix+"?cid="+global_cid,                
		datatype:"json",                
		mtype:'GET', 
		height:'300',
		width:'720',
		colNames:['家长姓名','宝宝姓名','关系','手机号码','服务的终止日期','加入时间','操作','cpid'],                
		colModel:[                    
		{name:'pname',index:'pname',width:100,align:'center'},                    
		{name:'name_student',index:'name_student',width:100,align:'center'},       
		{name:'relation',index:'relation',width:70,align:'center'},
		{name:'tel',index:'tel',width:100,align:'center'},
		{name:'edate',index:'tel',width:120,align:'center'},
		{name:'ctime_str',index:'ctime_str',width:100, sortable:false,align:'center'},
		{name:'option',index:'option',width:70,align:'center', sortable:false},
		{name:'cpid',index:'cpid',hidden:true}    
		],
		
		//autowidth:true,
		jsonReader: {
			root:"classParentList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#cmParPage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'ctime_str',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '',
		gridComplete:function(){
			var ids=jQuery("#cmParInfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i]; 
				del = "<a href='javascript:;' class='jqtrow' onclick='delTel_p(" + id + ")'>移除</a>"; 
				jQuery("#cmParInfo").jqGrid('setRowData', ids[i], { option: del });
			}
		}
	}).navGrid("#cmParPage", { edit: false, add: false, del: false, search: false });
}
function showCmParInfo2(){
	//家长列表
	$("#cmParInfo").jqGrid({                
		url:global_url+global_urijs+'cmmanage_searchClassParentList'+global_suffix+"?cid="+global_cid,                
		datatype:"json",                
		mtype:'GET', 
		height:'300',
		width:'720',
		colNames:['家长姓名','宝宝姓名','关系','手机号码','加入时间','操作','cpid'],                
		colModel:[                    
		{name:'pname',index:'pname',width:100,align:'center'},                    
		{name:'name_student',index:'name_student',width:100,align:'center'},       
		{name:'relation',index:'relation',width:70,align:'center'},
		{name:'tel',index:'tel',width:100,align:'center'},
		{name:'ctime_str',index:'ctime_str',width:100, sortable:false,align:'center'},
		{name:'option',index:'option',width:70,align:'center', sortable:false},
		{name:'cpid',index:'cpid',hidden:true}    
		],
		
		//autowidth:true,
		jsonReader: {
			root:"classParentList",
			page: "page",
			total: "page_count",
			records : "count",
			repeatitems: false
		},
		pager: jQuery('#cmParPage'),
		prmNames : {page:"page",sort: "sort"},
		rowNum: 10,
		//rowList: [10, 20, 30],
		sortname: 'ctime_str',
		hidegrid: false,
		sortorder: 'desc',
		viewrecords: true,
		caption: '',
		gridComplete:function(){
			var ids=jQuery("#cmParInfo").jqGrid('getDataIDs');
			for(var i=0; i<ids.length; i++){
				var id=ids[i]; 
				del = "<a href='javascript:;' class='jqtrow' onclick='delTel_p(" + id + ")'>移除</a>"; 
				jQuery("#cmParInfo").jqGrid('setRowData', ids[i], { option: del });
			}
		}
	}).navGrid("#cmParPage", { edit: false, add: false, del: false, search: false });
}


function chTel(id,isadmin){
	var funadd = function(data1){
		$("#cmTeaInfo").trigger("reloadGrid");
	};
	exeAjax(ajaxUrl(global_url+global_urijs+'cmmanage_updateClassTeacherAdmin'+global_suffix), funadd, {
		"ctid" :jQuery("#cmTeaInfo").jqGrid('getRowData', id).ctid,"isadmin_class":isadmin});

}

function delTel_t(id){
	 $(function() {$( "#compPrompt" ).dialog({
		modal: true,
		resizable: false,
		buttons: {
			"删除": function() {
				var funadd = function(data1){
					if(1==data1.s){
						 $().message("删除成功!");
						 $("#cmTeaInfo").trigger("reloadGrid");
						 $("#compPrompt").dialog( "close" );
					}else{
						 $().message("删除失败!");
					}
				};
				exeAjax(ajaxUrl(global_url+global_urijs+'cmmanage_deleteClassTeacher'+global_suffix), funadd, {"ctid" :jQuery("#cmTeaInfo").jqGrid('getRowData', id).ctid});
			},"取消": function() {
				$( this ).dialog( "close" );
			}
		}
		});
	});
}

function delTel_s(id){
	 $(function() {$( "#compPrompt" ).dialog({
		modal: true,
		resizable: false,
		buttons: {
			"删除": function() {
				var funadd = function(data1){
					if(1==data1.s){
						 $().message("删除成功!");
						 $("#cmStuInfo").trigger("reloadGrid");
						 $("#compPrompt").dialog( "close" );
					}else{
						 $().message("删除失败!");
					}
				};
				exeAjax(ajaxUrl(global_url+global_urijs+'cmmanage_deleteClassStudent'+global_suffix), funadd, {"csid" :jQuery("#cmStuInfo").jqGrid('getRowData', id).csid});
			},"取消": function() {
				$( this ).dialog( "close" );
			}
		}
		});
	});
}

function delTel_p(id){
	 $(function() {$( "#compPrompt" ).dialog({
		modal: true,
		resizable: false,
		buttons: {
			"删除": function() {
				var funadd = function(data1){
					if(1==data1.s){
						 $().message("删除成功!");
						 $("#cmParInfo").trigger("reloadGrid");
						 $("#compPrompt").dialog( "close" );
					}else{
						 $().message("删除失败!");
					}
				};
				exeAjax(ajaxUrl(global_url+global_urijs+'cmmanage_deleteClassParent'+global_suffix), funadd, {"cpid" :jQuery("#cmParInfo").jqGrid('getRowData', id).cpid});
			},"取消": function() {
				$( this ).dialog( "close" );
			}
		}
		});
	});
}


